package spring.cloud.simple.ui.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import spring.cloud.simple.ui.model.User;
import spring.cloud.simple.ui.service.UserService;

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @Value("${eureka.instance.hostname}")
    private String hostname;

    @Value("${eureka.server.port}")
    private int port;

    @RequestMapping(value = "/eurekaURL")
    public String getEurekaURL() {
        return hostname + ":" + port;
    }

    @RequestMapping(value = "/users", method = {RequestMethod.GET})
    public ResponseEntity<List<User>> findAll() {
        List<User> users = userService.findAll();
        return new ResponseEntity<>(users, HttpStatus.OK);
    }
}
